<template>
  <div class="content">
    <!--数据正在导出，请耐心等待~~~-->
    <el-progress :text-inside="true" :stroke-width="26" :percentage="percentage"></el-progress>
  </div>
</template>

<script>
  import {
    userManagement,
    changeCard,
    crmCardListForSpare,
    listForDisabled,
    removeCardList,
    coldCardList,
    crmCardList,
    selectTransactionRecord,
    returnCommissionList,
    realNameCheckList,
    orderManagement,
  } from '@/api/getData'

  export default {
    name: "exlDownload",
    data() {
      return {
        list: [],
        filterVal: [],
        info: {},
        percentage: 0,
      }
    },
    async created() {
      this.info = JSON.parse(this.$route.query.info);
      this.list = JSON.parse(this.$route.query.list);
      this.filterVal = JSON.parse(this.$route.query.filterVal);
      let obj = JSON.parse(this.$route.query.obj);
      let apiName = this.info.api;
      this.getList(apiName, obj);
    },
    methods: {
      getList(api, obj) {
        let a = import("@/api/getData");
        let total = parseInt(obj.page.size);
        let page = 0;
        if(total%2000===0){
          page = parseInt(total/2000);
        }
        else{
          page = parseInt(total/2000) + 1;
        }
        let p = parseFloat(100 / page).toFixed(2);

        console.log('page='+page)
        let list = [];
        a.then(async v => {
          for(let i=0;i<page;i++){
            console.log('i='+i)
            obj.page.size = 2000 + '';
            obj.page.current = i + '';
            let req = eval("v." + api);
            let back = await req(obj);
            if(back._result){
              list = new Array(...back.data.records);
              this.percentage = p * (i + 1);
              if(i+1===page){
                this.percentage = 100;
              }
            }
          }
          console.log(list)
          this.$exportToExcel(this.list, this.filterVal, list, this.info.name);

        });

        // a.then(async v => {
        //   console.log('----------');
        //   console.log(eval("v." + api));
        //   let req = eval("v." + api);
        //   console.log('----------');
        //   console.log(api);
        //   console.log('----------');
        //   console.log(obj.page.size);
        //   console.log('----------');
        //   console.log(obj);
        //   console.log('----------');
        //   let back = await req(obj);
        //   let data = [];
        //   console.log(back._result);
        //   if(back._result){
        //     data = back.data.records;
        //     if(api==='returnCommissionList'){
        //       console.log('-----------')
        //       console.log('-----returnCommissionList------')
        //       for(let item of data){
        //         item.reduceMoney = parseFloat(item.balance - item.applyMoney).toFixed(2); // 通过后金额
        //         if (item.dictStatus === 'C_WAIT') {
        //           item.reduceMoney = parseFloat(item.balance - item.applyMoney).toFixed(2)
        //         } else if (item.dictStatus === 'C_REFUSE' || item.dictStatus === 'C_THROUGH') {
        //           item.reduceMoney = '-';
        //         }
        //       }
        //     }
        //   }


        // })
      }
    }
  }
</script>

<style scoped>
  .content {
    width: 100%;
    min-height: 400px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #666;
  }
</style>
